// custom-tab-bar/index.js

const app = getApp()
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  
  data: {
    selected: 0,
    selectedColor: "#E8B300",
    color: "#fff",
    roleId: '',
    allList: [{
      /**
       * 学生tab
       */
      list1: [
        {
          pagePath: "/pages/squra/squra",
          iconPath: "/images/squra.png",
          selectedIconPath: "/images/squra_selected.png",
          text: "广场"
        }, {
          pagePath: "/pages/activity/activity",
          iconPath: "/images/activity.png",
          selectedIconPath: "/images/activity_selected.png",
          text: "活动"
        }, 
        {
          pagePath: "/pages/mine/mine",
          text: "我的",
          iconPath: "/images/mine.png",
          selectedIconPath: "/images/mine_selected.png"
        }
      ],
 
 
      /**
       * 教师tab  实际上跟学生一样，可以合并。也可以单独写，方便后期修改
       */
      list2: [{
        pagePath: "/pages/squra/squra",
        iconPath: "/images/squra.png",
        selectedIconPath: "/images/squra_selected.png",
        text: "广场"
      }, {
        pagePath: "/pages/activity/activity",
        iconPath: "/images/activity.png",
        selectedIconPath: "/images/activity_selected.png",
        text: "活动"
      }, 
      {
        pagePath: "/pages/mine/mine",
        text: "我的",
        iconPath: "/images/mine.png",
        selectedIconPath: "/images/mine_selected.png"
      }],
 
 
      list3: [{
        pagePath: "/pages/squra/squra",
        iconPath: "/images/squra.png",
        selectedIconPath: "/images/squra_selected.png",
        text: "广场"
      }, {
        pagePath: "/pages/activity/activity",
        iconPath: "/images/activity.png",
        selectedIconPath: "/images/activity_selected.png",
        text: "活动"
      }, {
        pagePath: "/pages/manager/manage/manage",
        text: "管理",
        iconPath: "/images/manager.png",
        selectedIconPath: "/images/manager_selected.png"
      },
      {
        pagePath: "/pages/mine/mine",
        text: "我的",
        iconPath: "/images/mine.png",
        selectedIconPath: "/images/mine_selected.png"
      }]
    }],
    list: []
  },
  attached() {
  
    const roleId = wx.getStorageSync('roleId')
    console.info(roleId)
    if (roleId == 1) {
      this.setData({
        list: this.data.allList[0].list1
      })
    }else if(roleId==2){
      this.setData({
        list: this.data.allList[0].list2
      })
    }else if(roleId==3){
      this.setData({
        list: this.data.allList[0].list3
      })
    }
    this.setData({
      selected: app.globalData.tabIndex
    })

  },
  /**
   * 组件的方法列表
   */
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset
      const url = data.path
      console.info("url"+url);
      wx.switchTab({ url })
      
      // this.setData({
      //   selected: data.index
      // })
      app.globalData.tabIndex = data.index
      console.info("当前tab"+this.data.selected);
    }
  }
})